package com.hd123.rumba.gwt.widget2e.client.form;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.TextBox;
import com.hd123.rumba.gwt.widget2.client.form.BeforeChangeListener;
import com.hd123.rumba.gwt.widget2.client.form.SourcesBeforeChangeEvents;

/**
 * 实现了SourcesBeforeChangeEvents的TextBox。<br>
 * <i>复制于com.hd123.rumba.gwt.widget2.form.RTextInput</i>
 * 
 * @author LiQi
 * @author lxm
 * 
 */
class RTextInput extends TextBox implements SourcesBeforeChangeEvents {

  private BeforeChangeListener beforeChangeListener;

  public RTextInput() {
    super();
    sinkEvents(Event.ONCHANGE);
  }

  public void onBrowserEvent(Event event) {
    switch (DOM.eventGetType(event)) {
    case Event.ONCHANGE:
      if (beforeChangeListener != null && !beforeChangeListener.beforeChange(this)) {
        event.stopPropagation();
        return;
      } else
        break;
    }

    super.onBrowserEvent(event);
  }

  public void setBeforeChangeListener(BeforeChangeListener listener) {
    this.beforeChangeListener = listener;
  }
}
